<template>
  <div class="goodsContent">
    <ul class="menu">
      <li class="lis" v-for="(item, index) in goods" :key="item.name" :style="{ fontSize, borderBottom }">
        <a :href="`#${index}`">{{ item.name }}</a>
      </li>
    </ul>
    <ol class="list">
      <li v-for="(item, index) in goods" :key="item.name">
        <h3 :id="index">{{ item.name }}</h3>
        <ul class="info">
          <li v-for="food in item.foods" :key="food.name">
            <div class="box">
              <div class="pic">
                <img :src="food.image" alt="" />
              </div>
              <div class="title">
                <h4>{{ food.name }}</h4>
                <span>￥{{ food.price }}</span>
              </div>
              <btns :item="food" type="0"></btns>
            </div>
          </li>
        </ul>
      </li>
    </ol>
    <div class="shopCar" @click="showCar">
      <p class="iconfont icon-gouwuche" id="p1"></p>
      <span class="sp1">￥{{ getPrice }}</span>
      <span class="sp2">另需配送费￥4元</span>
      <p class="p1">￥20起送</p>
    </div>
  </div>
</template>

<script>
import { mapActions, mapState } from "vuex";
import Btns from "./btns.vue";
import "../../font/iconfont.css"
export default {
  data() {
    return {
      // bg: this.sellerIofo.avatar,
      // carList: [],
      // num: 0
      borderBottom: "1px gray solid",
      fontSize: "12px",

    };
  },
  components: {
    Btns,
  },
  created() {
    this.getGoods();
  },
  computed: {
    ...mapState(["goods", "price", "carList"]),
    getPrice() {
      let num = 0;
      this.carList.forEach((item) =>{
        num += item.price * item.count;
      });
      return num;
    },
    // ...mapGetters(["getPrice"]),
  },
  methods: {
    ...mapActions(["getGoods"]),
    add(food) {
      // food.count++;
      if (!food.count) {
        food.count = 1;
      } else {
        food.count++;
      }
      this.$store.commit("setCarList", {
        item: food,
      });
    },
    increment(food) {
      food.count--;
    },
    showCar() {
      this.$store.commit("showCar");
    },
    change() {

    }
  },
};
</script>

<style lang="less" scoped>
.iconfont{
  color: gray;
  text-align: center;
  line-height: 40px;
  font-size: 25px;
  // background-color: gray;
}
.goodsContent {
  display: flex;
  height: 91%;
  background-color: white;
  overflow: hidden;

  .menu {
    flex: 0 0 80px;
    overflow-y: scroll;

    li {
      padding: 12px 12px 0 12px;
      height: 42px;
      background: #f6f7f8;
      overflow: hidden;
      color: gray;
      span {
        display: block;
        height: 41px;
        font-size: 12px;
        white-space: wrap;
        color: #333;
        border-bottom: 1px solid rgba(7, 17, 27, 0.1);
      }

      a {
        color: gray;
        // width: 10px;
        text-align: center;
        // line-height:41px ;
      }
      
    }
  }
  li:hover {
        color: black;
        background-color: #fff;
      }
  .list {
    flex: 1 1 auto;

    overflow-y: scroll;

    h3 {
      border-left: 4px #d9dde1 solid;
      background: #f3f5f7;
      height: 26px;
      line-height: 26px;
      padding-left: 12px;
      color: rgb(147, 153, 159);
      font-weight: 400;
      font-size: 12px;
    }

    .info li {
      padding: 0 18px;
      position: relative;

      .box {
        display: flex;
        padding: 18px 0;
        border-bottom: 1px rgba(1, 17, 27, 0.1) solid;

        .pic img {
          width: 100px;
        }

        .title {
          padding-left: 10px;
        }

        // .btns {
        //   position: absolute;
        //   right: 10px;
        //   bottom: 10px;
        //   display: flex;
        //   span {
        //     display: block;
        //     width: 24px;
        //     height: 24px;
        //     line-height: 20px;
        //     border-radius: 50%;
        //     font-size: 24px;
        //     text-align: center;
        //     font-weight: bold;
        //     color: rgb(0, 160, 220);
        //     border: 2px rgb(0, 160, 220) solid;
        //   }
        // }
      }
    }
  }

  .shopCar {
    display: flex;
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background: black;
    height: 53px;
    z-index: 200;
    // color: #fff;
    justify-content: space-between;

    .p1 {
      height: 100%;
      font-size: 15px;
      font-weight: 700;
      width: 105px;
      color: gray;
      text-align: center;
      line-height: 53px;
      background-color: rgba(120, 119, 119, 0.4);
    }

    .sp1 {
      font-weight: 900;
      font-size: 16px;
      color: gray;
      text-align: center;
      line-height: 53px;
      margin-left: 70px;
    }

    .sp2 {
      text-align: center;
      line-height: 53px;
      font-size: 12px;
      color: gray;
    }
  }
}
#p1{
  width: 40px;
  height: 40px;
  border-radius: 20px;
  border: 1px rgb(38, 37, 37) solid;
  position: absolute;
  top:-20px;
  left:6px;
  background-color: rgb(40, 38, 38);
}
</style>
